package cn.ikun.dhj.jdbc;

import java.sql.*;
import java.util.Set;

/**
 *
 */
public class JdbcUtils {
    public static int update(String sql)throws Exception{
        String url="jdbc:mysql://localhost:3306/shixi?useSSL=false";
        String admin="root";
        String pwd="root";
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection(url, admin, pwd);
        Statement statement = connection.createStatement();
        int i = statement.executeUpdate(sql);
        return i;
    }

    public static void select(String sql)throws Exception{
        String url="jdbc:mysql://localhost:3306/shixi?useSSL=false";
        String admin="root";
        String pwd="root";
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection(url, admin, pwd);
        Statement statement = connection.createStatement();
        ResultSet set = statement.executeQuery(sql);
        while (set.next()){
            System.out.print("id:"+set.getInt(1)+"  ");
            System.out.print("name:"+set.getString(2)+"  ");
            System.out.println("pwd:"+set.getString(3)+"  ");
        }


    }

}
